let nameIndex = 0
function getDefaultName() {
  nameIndex++;
  return 'keep-name-'+nameIndex
}

//给每个页面组件设置name以便keep-alive组件设置include
export const  setDefaultComponentName = (arr: Array<any>) => {
  arr.forEach(item => {
    if (item.children) {
      setDefaultComponentName(item.children)
    } else if (item.component) {
      if (item.meta && item.meta.keepAlive === false) {
        return
      }
      const keepName = getDefaultName() // 生成唯一的组件名
      if (typeof item.component === 'function') {
        const func = item.component
        item.component = async () => {
          const result = await func()
          const node = result.default
          if (!node.name) {
            node.name = keepName
          }
          return result
        }
      } else {
        if (!item.component.name) {
          item.component.name = keepName
        }
      }
    }
  });
}